package com.lineage;

import com.eric.gui.J_Main;
import com.lineage.commons.system.LanSecurityManager;
import com.lineage.config.Config;
import com.lineage.config.ConfigAi;
import com.lineage.config.ConfigAlt;
import com.lineage.config.ConfigBad;
import com.lineage.config.ConfigBoxs;
import com.lineage.config.ConfigCharSetting;
import com.lineage.config.ConfigClan;
import com.lineage.config.ConfigDarkElfSkill;
import com.lineage.config.ConfigDescs;
import com.lineage.config.ConfigDragonKnightSkill;
import com.lineage.config.ConfigDrop;
import com.lineage.config.ConfigElfSkill;
import com.lineage.config.ConfigGuaji;
import com.lineage.config.ConfigIllusionstSkill;
import com.lineage.config.ConfigIpCheck;
import com.lineage.config.ConfigKill;
import com.lineage.config.ConfigKnightSkill;
import com.lineage.config.ConfigOther;
import com.lineage.config.ConfigPrinceSkill;
import com.lineage.config.ConfigQuest;
import com.lineage.config.ConfigRate;
import com.lineage.config.ConfigRecord;
import com.lineage.config.ConfigSQL;
import com.lineage.config.ConfigServer;
import com.lineage.config.ConfigWho;
import com.lineage.config.ConfigWizardSkill;
import com.lineage.config.Config_Pc_Damage;
import com.lineage.config.Configtf;
import com.lineage.config.Configtype;
import com.lineage.list.Announcements;
import com.lineage.server.GameServer;
import com.lineage.server.utils.DBClearAllUtil;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.LogManager;
import org.apache.log4j.PropertyConfigurator;

public class Server {
  public static void main(String[] args) throws Exception {
    System.out.println("【Welcome to Lineage】");
    CompressFile bean = new CompressFile();
    try {
      File file = new File("./back");
      if (!file.exists())
        file.mkdir(); 
      String nowDate = (new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss")).format(new Date());
      bean.zip("./loginfo", "./back/" + nowDate + ".zip");
      File loginfofile = new File("./loginfo");
      String[] loginfofileList = loginfofile.list();
      String[] array;
      int length = (array = loginfofileList).length;
      int i = 0;
      while (i < length) {
        String fileName = array[i];
        File readfile = new File("./loginfo/" + fileName);
        if (readfile.exists() && !readfile.isDirectory())
          readfile.delete(); 
        i++;
      } 
    } catch (IOException e2) {
      System.out.println("资料夹不存在: ./back 已经自动建立!");
    } 
    boolean error = false;
    try {
      InputStream is = new BufferedInputStream(new FileInputStream("./config/logging.properties"));
      LogManager.getLogManager().readConfiguration(is);
      is.close();
    } catch (IOException e3) {
      System.out.println("档案遗失: ./config/logging.properties");
      error = true;
    } 
    try {
      PropertyConfigurator.configure("./config/log4j.properties");
    } catch (Exception e) {
      System.out.println("档案遗失: ./config/log4j.properties");
      System.exit(0);
    } 
    try {
      Config.load();
      ConfigAlt.load();
      ConfigCharSetting.load();
      ConfigOther.load();
      Config_Pc_Damage.load();
      ConfigRate.load();
      ConfigSQL.load();
      ConfigRecord.load();
      ConfigWho.load();
      ConfigBad.load();
      Configtype.load();
      ConfigAi.load();
      Configtf.load();
      ConfigIpCheck.load();
      ConfigClan.load();
      ConfigGuaji.load();
      ConfigPrinceSkill.load();
      ConfigKnightSkill.load();
      ConfigElfSkill.load();
      ConfigWizardSkill.load();
      ConfigDarkElfSkill.load();
      ConfigDragonKnightSkill.load();
      ConfigIllusionstSkill.load();
    } catch (Exception e) {
      System.out.println("CONFIG 资料加载异常!" + e);
      error = true;
    } 
    System.out.println("-------------------------------------------------- ");
    System.out.println("Lineage【版本Ver_2100381916】 ");
    System.out.println("-------------------------------------------------- ");
    System.out.println("读取设定中...");
    Thread.sleep(2000L);
    if (error)
      System.exit(0); 
    DatabaseFactoryLogin.setDatabaseSettings();
    DatabaseFactory.setDatabaseSettings();
    DatabaseFactoryLogin.get();
    DatabaseFactory.get();
    ConfigBoxs.get();
    ConfigKill.get();
    ConfigDrop.get();
    ConfigDescs.get();
    ConfigQuest.load();
    ConfigServer.loadDB();
    if (ConfigServer.DBClearAll)
      DBClearAllUtil.start(); 
    if (Config.NEWS)
      Announcements.get(); 
    if (Config.GUI)
      J_Main.getInstance().setVisible(true); 
    LanSecurityManager securityManager = new LanSecurityManager();
    System.setSecurityManager((SecurityManager)securityManager);
    String osname = System.getProperties().getProperty("os.name");
    if (osname.lastIndexOf("Linux") != -1)
      Config.ISUBUNTU = true; 
    GameServer.getInstance().initialize();
  }
}
